package com.tencent.wxcloudrun.service;

import com.alibaba.fastjson2.JSON;
import com.tencent.wxcloudrun.dao.ShopMapper;
import com.tencent.wxcloudrun.model.Goods;
import com.tencent.wxcloudrun.model.Shop;
import com.tencent.wxcloudrun.model.ShopListReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: ShopService
 * Package: com.tencent.wxcloudrun.service
 * Description:
 *
 * @Date: 2023/1/23 2:04 PM
 * @Author: wht
 */
@Slf4j
@Service
public class ShopService {
    @Autowired
    ShopMapper shopMapper;

    public void addOneShop(Shop shop) {
        String str = JSON.toJSONString(shop.getGoods_list());
        shop.setGoods_list_json(str);
        shopMapper.addOneShop(shop);
    }

    public void updateOneShopById(Shop shop) {
        if (shop.getGoods_list().size() > 0) {
            String str = JSON.toJSONString(shop.getGoods_list());
            shop.setGoods_list_json(str);
        }


        shopMapper.updateOneShopById(shop);
    }

    public List<Shop> getShopList(ShopListReq shop) {
        List<Shop> shopList = shopMapper.getShopList(shop);
        for (Shop shop1 : shopList) {
            List<Goods> goodsList = JSON.parseArray(shop1.getGoods_list_json(), Goods.class);
            shop1.setGoods_list(goodsList);
        }
        return shopList;
    }

}
